%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Program: printMoments
% Purpose: print targeted + nontargeted moments of ALO model to screen
% Project: Rust Belt
% Date:    April 2, 2022
% By:      David Lagakos, Martin Shu, Simeon Alder, Lee Ohanian
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clocknow = clock;
disp(' ');
disp(' ');
disp(' Parameters and Moments for Rust Belt Model ');
% disp(' ');
% disp([' Parameter:' diaryName ]);
disp(' ');
disp([' Current Date/Time: ', num2str(clocknow(1,1),'%.0f'),' ',num2str(clocknow(1,2),'%.0f'),' ',num2str(clocknow(1,3),'%.0f'),' ',num2str(clocknow(1,4),'%.0f'),':',num2str(clocknow(1,5),'%.0f')   ]);
disp(' ');
disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp('  Parameter Values  ');
disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp(' ');
disp(' ');
disp([' 1. lambda              = ' num2str(lambda,'%.3f')])
disp(' ');
disp([' 2. sigma_z0            = ' num2str(sigmazH0,'%.3f')])
disp(' ');
disp([' 3. alpha               = ' num2str(alpha,'%.3f')])
disp(' ');
disp([' 4. s                   = ' num2str(s,'%.3f')])
disp(' ');
disp(' --------------------------------------------------------------------')
disp([' 5. tau_0               = ' num2str(tau0,'%.3f')])
disp(' ');
disp([' 6. delta_tau           = ' num2str(delta_tau,'%.3f')])
disp(' ');
disp([' 7. zeta                = ' num2str(zeta_initial,'%.3f')])
disp(' ');
disp([' 8. rho                 = ' num2str(rho,'%.3f')])
disp(' ');
disp(' --------------------------------------------------------------------')
disp([' 9. sigma               = ' num2str(sigma,'%.3f')])
disp(' ');
disp([' 10. sigma_eps          = ' num2str(sigmazH,'%.3f')])
disp(' ');
disp([' 11. phi_R              = ' num2str(phi_R,'%.3f')])
disp(' ');
disp([' 12. phi_S              = ' num2str(phi_S,'%.3f')])
disp(' ');
disp('-------------------------------------------------------------')
disp([' ngoods                 = ' num2str(ngoods,'%.0f')])
disp(' ');
disp([' gamma                  = ' num2str(gamma,'%.1f')])
disp(' ');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Run same regression as in data
%%%      e.g log cumulative employment growth on conflict rate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%%% From data, average state-industry-year conflict involves multiple firms
num_firms_per_strike_avg = 3.334623;

%%% In model, only 1 firm per state-industry-year conflict, so need to
%%% scale up
avg_strike_rate = mean(strike_t(1,:,9:28),3)*num_firms_per_strike_avg;

%%% Regress cum emp growth on conflict, and a constant
X = [ones(Par.ngoods,1) avg_strike_rate'];
l_51 = l_t(1,:,51)+l_t(2,:,51);
l_1 = (l_t(1,:,1) + l_t(2,:,1));
cum_emp_growth = (log(l_51) - log(l_1));
Y = cum_emp_growth';
[B, BINT, R, RINT, STATS] = regress(Y,X);
B(2,1);
    

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Print Table of Model vs Data moments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Model moments

model_initial_RB_emp_share = 100*RB_labor_share(1,1);
model_mfg_inv_va = 100*mean(shiftdim(sum(i_t(1,:,:))./(sum(p_t(1:2,:,:).*y_t(1:2,:,:),[1 2]))));
model_mfg_Y_N_growth = 100*(mean(shiftdim(mean((z_t(1,:,2:nPeriods)./z_t(1,:,1:nPeriods-1)))))-1);
model_RB_import_share_1958 = 100*RB_import_share(1,9);
model_RB_import_share_1990 = 100*RB_import_share(1,41);
model_agg_import_share_1958 = 100*Agg_import_share(1,9);
model_agg_import_share_1990 = 100*Agg_import_share(1,41);
model_RB_wage_prem = 100*mean(wage_premium_RB(1:31,1));
model_RB_strike_pct = 100*mean(strike_rate_RB_t(1,1,9:28));
model_ROC_strike_pct = 100*mean(strike_rate_SB_t(1,1,9:28));
model_slope_conflict = B(2,1);
model_var_initial_log_emp = var(log(l_t(1,:,1)+l_t(2,:,1)));

labor_share_t = 100.*shiftdim(1 + sum(rent_t(1,:,:),2) - kappa*sum(strike_t(1,:,:).*l_t(1:2,:,:),[1 2]))./GDP_1(:,1);
model_labor_share = mean(labor_share_t(1:31));

model_moments = [...%     model_initial_RB_emp_share...
    model_mfg_inv_va...
    model_mfg_Y_N_growth...
    model_RB_import_share_1958...
    model_RB_import_share_1990...
    model_agg_import_share_1958...
    model_agg_import_share_1990...%     model_RB_wage_prem...
    model_RB_strike_pct...
    model_ROC_strike_pct...
    model_slope_conflict...
    model_var_initial_log_emp];
    

%%% Empirical moments

initial_RB_emp_share = 51.3;
mfg_inv_va = 16.0;
mfg_Y_N_growth = 2.8;
RB_import_share_1958 = 4.5;
RB_import_share_1990 = 58.6;
agg_import_share_1958 = 3.8;
agg_import_share_1990 = 25.8;
RB_wage_prem = 12.0;
RB_strike_pct = 19.2;
ROC_strike_pct = 2.7;
slope_conflict = -0.46;
var_initial_log_emp = 3.2;

targets = [...%     initial_RB_emp_share ...
    mfg_inv_va ...
    mfg_Y_N_growth ...
    RB_import_share_1958 ...
    RB_import_share_1990 ...
    agg_import_share_1958 ...
    agg_import_share_1990 ...%     RB_wage_prem ...
    ROC_strike_pct ...
    RB_strike_pct ...
    slope_conflict ...
    var_initial_log_emp];


%%% Non-targeted moments
avg_RB_growth_rate = 100*(mean(z_t(1,1:Par.nRBgoods,2:51)./z_t(1,1:Par.nRBgoods,1:50),'all') - 1);
avg_RB_growth_rate_pre = 100*(mean(z_t(1,1:Par.nRBgoods,2:35)./z_t(1,1:Par.nRBgoods,1:34),'all') - 1);
avg_ROC_growth_rate_pre = 100*(mean(z_t(1,Par.nRBgoods+1:Par.ngoods,2:35)./z_t(1,Par.nRBgoods+1:Par.ngoods,1:34),'all') - 1);
avg_growth_rate_pre = 100*(mean(z_t(1,:,2:35)./z_t(1,:,1:34),'all') - 1);
avg_RB_growth_rate_post = 100*(mean(z_t(1,1:Par.nRBgoods,36:51)./z_t(1,1:Par.nRBgoods,35:50),'all') - 1);
RB_growth_differential_pre = avg_growth_rate_pre - avg_RB_growth_rate_pre;

disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp('  Moments in Model + Data ');
disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp('  MOMENT                                            MODEL      DATA         RELATED PARAMETER')
disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp(' ');
disp([' 1. Initial mfg empl. share RB                      ' num2str(model_initial_RB_emp_share,'%.6f'), '       51.3            lambda' ])
disp(' ');
disp([' 2. Avg mfg firm investment / VA                    ' num2str(model_mfg_inv_va,'%.6f'), '       16.0              s' ])
disp(' '); 
disp([' 3. Avg mfg firm Y/L growth                         ' num2str(model_mfg_Y_N_growth,'%.6f'), '        2.8             alpha' ])
disp(' ');
disp([' 4. Rust Belt import share, 1958 (%)                ' num2str(model_RB_import_share_1958,'%.6f'), '        4.5             tau_0' ])
disp(' ');
disp([' 5. Rust Belt import share, 1990 (%)                ' num2str(model_RB_import_share_1990,'%.6f'), '       58.6             zeta' ])
disp(' ');
disp([' 6. Labor share of GDP, 1950-1980 (%)               ' num2str(model_labor_share,'%.6f'), '       70.7            sigma' ])
disp(' ');
disp([' 7. Aggregate import share, 1990 (%)                ' num2str(model_agg_import_share_1990,'%.6f'), '       25.8           delta_tau' ])
disp(' ');
disp([' 8. Rust Belt wage premium in mfg, 1950-1980        ' num2str(model_RB_wage_prem,'%.6f'), '       12.0            phi_R' ])
disp(' ');
disp([' 9. Rust Belt strike % in mfg, 1958-1977            ' num2str(model_RB_strike_pct,'%.6f'), '       19.2             sigma_eps' ])
disp(' ');
disp([' 10. ROC avg strike % in mfg, 1958-1977             ' num2str(model_ROC_strike_pct,'%.6f'), '         2.7             phi_S' ])
disp(' ');
disp([' 11. Regress, slope log empl. growth on conflict    ' num2str(model_slope_conflict,'%.6f'), '      -0.46             rho' ])
disp(' ');
disp([' 12. Var(state-ind. log empl 1950)                  ' num2str(model_var_initial_log_emp,'%.6f'), '         3.2            sigmaz0' ])
disp(' ');
disp(' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
disp(' ');
disp([' N1. Average RB firm growth                         ' num2str(avg_RB_growth_rate,'%.6f'), '         2.6              ' ])
disp(' ');
disp([' N2. Average RB firm growth, pre 1985               ' num2str(avg_RB_growth_rate_pre,'%.6f'), '         2.0              ' ])
disp(' ');
disp([' N3. Average RB firm growth, post 1985              ' num2str(avg_RB_growth_rate_post,'%.6f'), '         4.2              ' ])
disp(' ');
disp([' N4. Avg. growth differential, pre 1985, US - RB    ' num2str(RB_growth_differential_pre,'%.6f'), '         0.6              ' ])
disp(' ');
 
    

